<script lang="ts" setup>
import { onLaunch  } from '@dcloudio/uni-app';
import { userData } from './type/user';
import store from './store';
import { createSocket } from './api/webSocket';
import { InitSender } from './type/chat';
import chatStore from './store/chat';
onLaunch(()=>{
	//本地缓存已存在登入信息 直接放入store中
	try{
		//获取消息列表对象
		const senderList:Array<InitSender>=uni.getStorageSync('senderList');
		if(senderList){
			chatStore.senderList=[
				...senderList
			]
		}
		//获取本地缓存的用户信息
		const user:userData=uni.getStorageSync('userInfo');
		if(user){
			store.state.nickname=user.nickname;
			store.state.pkId=user.pkId;
			//获取到redis消息 存入本地缓存
			chatStore.initRedisChatList(user.pkId);	
			store.state.headimgurl=user.headimgurl;
			// 开启webSocket连接
		    createSocket();
			}
	
	}catch(e){
		console.log('提取用户信息失败');
	}
})
</script>

<style lang="scss">
	/*每个页面公共css */
	@import '@/uni_modules/uni-scss/index.scss';
	/* #ifndef APP-NVUE */
	@import '@/static/customicons.css';
	// 设置整个项目的背景色
	page {
		background-color: #f5f5f5;
	}

	/* #endif */
	.example-info {
		font-size: 14px;
		color: #333;
		padding: 10px;
	}
</style>
